﻿/**
 * 
 * Copyright 2009, 2010 Mike Jamer [email: mikejamer@gmail.com ]
 * 
 * This File is part of Moose IRC
 * 
 * MooseIRC is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * 
 * MooseIRC is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with MooseIRC.  If not, see <http://www.gnu.org/licenses/>.
 * 
 */

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using moose.irc.extension;

namespace moose.irc.actions.commands.CTCP {

    /// <summary>
    /// IRC Ping Command, is used to call the request in a special way, because we want to keep track of how long
    /// it takes the response to come in
    /// </summary>
    [CLSCompliant(true)]
    [Action(Type = ActionTypes.Command,
        Name = "moose-std-cmd-ctcp-ping",
        Description = "Sends CTCP Ping Command",
        Version = "0.1",
        Author = "Mike MacKenzie-Jamer<email:mikejamer@gmail.com")]
    [Trigger(TriggerText = "CTCP-CMD-PING")]
    public sealed class CTCPPingCommand : IrcAction {

        /// <summary>
        /// Tracks user request times
        /// </summary>
        public static Dictionary<IrcUser, DateTime> RequestTimes { get; set; }

        public override IrcSessionStates valid_states() {
            return IrcSessionStates.Registered;
        }

        public override void action(IrcSession session, IrcMessage message) { //This is here to intercept the message, so we can track times
            if (RequestTimes == null) RequestTimes = new Dictionary<IrcUser, DateTime>();
            IrcUser target = (IrcUser)session.get_entity(message.Arguments[0]); //This may not be the correct argument
            RequestTimes[target] = DateTime.Now;
            session.send_raw("PRIVMSG " + message.Arguments[0] + " " + ((char)0x1).ToString() + "PING" + ((char)0x1).ToString());
            return;
        }
    }
}
